package game.monster
{
	import com.yzy.models.SetLibs;
	
	import flash.geom.Rectangle;
	
	import game.bejeweled.BejeweledBlock;
	
	import models.MonsterModel;
	import models.ProfileModel;
	
	import starling.display.Sprite;
	import starling.textures.Texture;
	
	public class MonstersBlock extends Sprite
	{
		
		private var left:Number;
		private var right:Number;
		private var top:Number;
		private var bottom:Number;
		
		private var rect:Rectangle;
		
		public function MonstersBlock()
		{
			super();
		}
		
		public function init(xml:XMLList):void{
			var msTotal:int=xml.length();
			rect=new Rectangle(xml.@left,xml.@top,xml.@right,xml.@bottom);
			for (var i:int = 0; i < msTotal; i++) 
			{
				var msModel:MonsterModel=new MonsterModel();
				msModel.ballName=xml.monster[0].@image;
				msModel.ballTexture=Texture.fromBitmapData(SetLibs.getBitmapData(msModel.ballName));
				ProfileModel.instant.monsterModelVec[i]=msModel;
			}
			//
			createMonster();
		}
		
		public function createMonster():void{
			var monster1:Monster=new Monster("monster1",rect,4);
			ProfileModel.instant.monsterVec.push(monster1);
			
			monster1.x= 200
			monster1.y= 100;
			this.addChild(monster1);
			ProfileModel.instant._runVec.push(monster1);
		}
		
		//*****************************************************
		// Singleton 
		//*****************************************************
		private static var _instant:MonstersBlock;
		public static function get instant():MonstersBlock
		{
			if(null == _instant)
			{
				_instant =  new MonstersBlock();
			}
			return _instant;
		}
	}
}